/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {Thrift} from '@ohos/thrift'
import CalculatorClient from '../../common/calculator/Calculator';
import {WorkDouble, Operation
} from '../../common/calculator/tutorial_types';

export default {
    data: {
        doubleAdd: '',
        doubleSubtract: '',
        doubleMultiply: '',
        doubleDivide: ''
    },
    onInit() {
    },
    onButtonClick() {
        var transport = new Thrift.Transport("http://192.168.0.109:9090/thrift/service/tutorial/");
        var protocol = new Thrift.Protocol(transport);
        var client = new CalculatorClient(protocol);

        var that = this;

        var workDoubleAdd = new WorkDouble()
        workDoubleAdd.num1 = 1.07;
        workDoubleAdd.num2 = 5.93;
        workDoubleAdd.op = Operation.ADD;
        client.calculateDouble(1, workDoubleAdd, function (result) {
            if (result) {
                that.doubleAdd = result;
            }
        });

        var workDoubleSubtract = new WorkDouble()
        workDoubleSubtract.num1 = 10.07;
        workDoubleSubtract.num2 = 5.93;
        workDoubleSubtract.op = Operation.SUBTRACT;
        client.calculateDouble(1, workDoubleSubtract, function (result) {
            if (result) {
                that.doubleSubtract = result;
            }
        });

        var workDoubleMultiply = new WorkDouble()
        workDoubleMultiply.num1 = 1.07;
        workDoubleMultiply.num2 = 5.93;
        workDoubleMultiply.op = Operation.MULTIPLY;
        client.calculateDouble(1, workDoubleMultiply, function (result) {
            if (result) {
                that.doubleMultiply = result;
            }
        });

        var workDoubleDivide = new WorkDouble()
        workDoubleDivide.num1 = 5.00;
        workDoubleDivide.num2 = 5.00;
        workDoubleDivide.op = Operation.DIVIDE;
        client.calculateDouble(1, workDoubleDivide, function (result) {
            if (result) {
                that.doubleDivide = result;
            }
        });
    }
}
